
	Tally = function(){};
	Tally.init = function(subModel){
		Tally.loadBoard();
		Tally.loadHome();
		Help.show(1001,0);
	}
	
	Tally.search2DPie = function(){

		$.getJSON("/tally/home_pie.php", function(data){
			var seriesData = [];
			for(var i in data.rows){
				var row = data.rows[i];
				seriesData.push({
					name: row.name,
					y: parseFloat(row.sumOut)
				});
			}
			Highcharts.chart('month_chart', {
				chart: {
					plotBackgroundColor: null,
					plotBorderWidth: null,
					plotShadow: false,
					type: 'pie'
				},
				title: {
					text: '本月消费'
				},
				tooltip: {
					pointFormat: '{series.name}: <b>{point.y:.2f}</b>'
				},
				plotOptions: {
					pie: {
						allowPointSelect: true,
						cursor: 'pointer',
						dataLabels: {
							enabled: true,
							format: '<b>{point.name}</b>: {point.y:.2f}'
						}
					}
				},
				series: [{
					name: '本月消费',
					colorByPoint: true,
					data: seriesData
				}]
			});
		});
	}
	
	 /*
	  *切换左边一栏
	 */
	Tally.activeBoard =function(disId,hidId){
	   $('#'+disId).find('li').removeClass('active');
   	   $('#'+hidId).find('li input:checkbox').removeAttr('checked');
		
	   $("input[id=subjectId],[clear=true]").val('');
	   $("#"+disId).show(); //显示
	   $("#"+hidId).hide(); //隐藏
	 }
	
	Tally.activeStaticBoard = function(disId,hidId){
		$("#"+disId).show(); //显示
		$("#"+hidId).hide(); //隐藏
	}
	
	//每记一笔帐相应清空如下值
	Tally.clear = function(args){
		$("#addForm #remark").val('');
		$("#addForm #amount").val('');
		$("#addForm #tagName").val('');
	}
	//账目删除
	Tally.onDelete = function(oid){
       deleteRow('../tally/home_delete.php?oid='+oid+rnd(),function(){
    		if(CM.afterSubmit0){CM.afterSubmit0();}
    		CM.afterSubmit();	
       });
	}
	 
	//加载面板.
	Tally.loadBoard= function(){
		
		//刷新之前判断是哪个为选中的状态
		var mode = $('#tally_board #category').attr('class'); 
		if(mode=='active'){ //收支类别为激活状态
			//不刷新,这里比较复杂，暂时不写
			 $('#tally_board #category').removeClass('active');
			$('#tally_board #account').addClass('active');
			Tally.activeBoard('account_board','category_board');
			$('#board').load('../tally/board.php?method='+rnd(),'',function(){
				CM.initPullDown($('div.tally_btn'));
			}); 
		}else {
			$('#board').load('../tally/board.php?method='+rnd(),'',function(){
				CM.initPullDown($('div.tally_btn'));
			});	
		}
		
	}
	
	
	//加载主页
	Tally.loadHome = function(){	    
	    $('#main').load('../tally/home.php?method=execute'+rnd(),'',function(){
	    	Tally.search2DPie();
	    	//加载remind
	    	Remind.search();
	    });
	}
	
	//加载货币名称
	Tally.showCurrencySymbol = function(flag){
		//CM.alert(flag);
		var oid = $('#subjectId0').val();
		var mateId = $('#subjectId1').val();
		submitReq('../tally/exchange.php?method=getCurrencyName&subjectId0='+oid+'&subjectId1='+mateId+'&flag='+flag+rnd(),function(data){
			if(flag=='0'){
				$('#currencySymbolOut').text(data.currencyName);
			}else if(flag=='1'){
				$('#currencySymbolIn').text(data.currencyName);
			}
			$('#exchangeRate').val(ForDight(data.rate,4));
		});
	}
	
	//显示收益选项
	Tally.goChangeInterest = function(subjectId){
		var coSubjectId;
		submitReq('../tally/receipt.php?method=getCoSubjectId&subjectId='+subjectId+rnd(),function(data){
			//CM.alert(data.id);
			coSubjectId = data.id;
			if(coSubjectId=='' || coSubjectId==undefined || coSubjectId==null){
				//$('#interestLabel').show();
				$('#subjectId2').removeAttr('disabled'); 
			}else{
				//$('#interestLabel').hide();
				$('#subjectId2').val(coSubjectId);
				$('#subjectId2').attr('disabled','disabled'); 
			}
		});
	}
	
	/**
	 * 验证账户来判断人员是否可以为空
	 * 1.作为回调函数载入
	 * 2.如果人员为空，通过subjectId判断是否需要人员
	 */
	Tally.validatePayee=function(me,num,callback){
		var form=$(me).parents('form:first');
		if($(form).find('select[name=payeeId]').val()){
			callback();
			return;
		}
		var params="&num="+num;
		for(i=0;i<num;i++){
			params = params+"&subjectId"+i+"="+$(form).find('select[name=subjectId'+i+']').val();
		}
		//params = '{'+params+'}';
		
		callback();
	}
	
	Tally.getPayeeAttr =function(subjectId){
		
	}
	
	Tally.reList = function(){
		var accountType = $('#accountType').val();
		var subjectId = $('#subjectId').val();
		//alert(accountType,subjectId);
		Tally.list(accountType,subjectId);
	}
	
	 //打开修改页面
   Tally.goEdit=function(oid,actionType,bizType,isCopyFlag){
	    var title = "";
	    var url = "";
	    var showCode ="";
	   	//alert('oid='+oid+',actionType='+actionType+',bizType='+bizType);
	     switch   (actionType){  
	     //对应开户 要根据其accountType来决定修改
	      case '3':
	    	  title="收入";
	    	  url = "../tally/income.php?method=edit&";
	    	  if(isCopyFlag=='0'){ showCode = 1040;}
	    	  if(isCopyFlag=='1'){ showCode = 1072;}
	      		break;
	      case '4':
	    	  title="支出";
	    	  url = "../tally/expense.php?method=edit&";
	    	  if(isCopyFlag=='0'){ showCode = 1043;}
	    	  if(isCopyFlag=='1'){ showCode = 1075;}
	    	
	      		break;
	      case '2':
	    	  title="转账/取钱...";
	    	  url = "../tally/transfer.php?method=edit&";
	    	  if(isCopyFlag=='0'){ showCode = 1048;}
	    	  if(isCopyFlag=='1'){ showCode = 1075;}
	      		break;		
	      default:
	            CM.alert('该账目不能编辑,您可以删除后重新录入.');	
	      		break;
	      }    
	     
	     if(url!=""){
	    	 if(isCopyFlag!='1') title = "修改"+title;
	    	 url = url+'oid='+oid+'&bizType='+bizType+'&isCopyFlag='+isCopyFlag+rnd();
	    	 if(actionType=='6' || actionType=='7' || bizType=='15' || bizType=='23'){
		    	 CM.open(url,{title:title,size:WINDOW_G},function(){
		    		var amount = $('div.content input[name=totalAmount]').val();
		    		if(amount!=undefined){
		    			$('div.content input[name=amount]').attr('readonly','readonly');
		    			$('div.content input[name=amount]').css('background-color','#d0d0d0');
		    		}
			        Help.show(showCode,1);
			     });
	    	 }else{
		    	 CM.open(url,{title:title},function(){
			        Help.show(showCode,1);
			     });
	    	 }
	     }	
   }
   
   //更改账目的状态
   /*Tally.updatePaidStatus = function(code){
	   if (_code) return;
	   submitReq('../tally/creditDebt_updatePaidStatus.php?voucherId='+code+rnd(),function(data){
	   		CM.afterSubmit0();
	   		CM.afterSubmit();
	   });
	   
   }*/
   
   //刷新主页面
   Tally.refresh = function(){
       Tally.loadBoard();
   }
   
   Tally.showRemark = function(me){
	   $(me).hide();
	   $(me).parents('td:first').find('textarea:first').show();
   }
   
   Tally.showGain = function(me){
	   //CM.alert($(me).parents('tr:first'));
	   $('tr:hidden').show();
	   $(me).parents('tr:first').hide();
   }

   Tally.showFrequence = function(me){
	   //CM.alert($(me).parents('tr:first'));
	   $('tr:hidden').show();
	   $(me).parents('tr:first').hide();
	   $(me).parents('form:first').find("input[name='flag']").val('1');
	   //CM.alert($(me).parents('form:first').find("input[name='flag']").val());
   }
	
   Tally.showActivity = function(me){
	   var td = $(me).parents("td:first");
	   var input=$(td).find("input[name='activity']");
	   var inputAt=$(td).find("input[name='inputActivity']");
	   var span = $(td).find("span:first");
	   if(inputAt.css('display')=='none'){
		   inputAt.show();
		   inputAt.val(input.val());
		   $(span).hide();
		   inputAt.focus();
	   }else{
		   inputAt.hide();
		   $(span).show();
		   if(trim(inputAt.val())==''){
			   $(span).find('a').html(input.val());
		   }else{
			   $(span).find('a').html(inputAt.val());
			   input.val(inputAt.val());
		   }
	   }
   }
   
   Tally.hideRelatedVoucher = function(me){
	   $('div.content #load_related_voucher').show();
	   $(me).hide();
	   $('div.content #related_tally').html('');
	   if($('div.content input[name=amount]').attr('readonly')){
		   $('div.content input[name=amount]').removeAttr('readonly');
	   }
	   $('div.content input[name=amount]').css('background-color','#ffffff');
	   $('div.content input[name=amount]').val('');
   }
   
   Tally.list = function(accountType,subjectId){
	   switch(accountType){
	   		case '0':
	   		case '1':
	   			Cash.list(subjectId);
	   			break;
	   			
	   		case '2':
	   			Credit.list(subjectId);
	   			break;
	   			
	   		case '6':
	   			CreditDebt.summryList(subjectId);
	   			Help.show(1106,1);
	   			break;
	   		
	   		case '14':
	   		
	   		case '7':
	   			CreditDebt.summryList(subjectId);
	   			Help.show(1107,1);
	   			break;
	   		case '13':
	   			CreditDebt.summryList(subjectId);
	   			break;
	   		
	   		case '8':
	   			Stock.list(subjectId);
	   			break;
	   			
	   		case '9':
	   			Fund.list(subjectId);
	   			break;
	   			
	   		
	   		default:
	   			break;
	   
	   }
	   Help.show(1104,0);
	   
   }
    
/*******************日常流水 1.按照账户显示;2.按照收支类别显示*********************/   
	Flow = function(){}
	Flow.pg = new Page('listtb');
	
	Flow.listByAccount = function(parm){
		Flow.pg.params='';
		$('#main').load('../tally/flow_accountList.php?'+rnd(),function(){     
			Flow.searchByAccount();
			if(parm=='0'){ Help.show(1034,0);}
			if(parm=='1'){ Help.show(1104,0);}
			
		});
	}
	
	Flow.searchByAccount = function(){
		 $('#dataView').html(LOADING);
		 url = '../tally/flow_accountListQry.php?';
		 if (Flow.pg.params && !Flow.pg.flag) {url +=Flow.pg.params;}
         submitSearch('flowSchForm',url+rnd(),'dataView',function(){
        	 Flow.pg.query = Flow.searchByAccount; 
        	 Flow.pg.init();
         });
	}
	
	Flow.listByCategory = function(){
		Flow.pg.params='';
		$('#main').load('../tally/flow_categoryList.php?'+rnd(),'',function(){     
			Flow.searchByCategory();
			 Help.show(1105,0);
		});
	}
	
	Flow.searchByCategory = function(){
		 $('#dataView').html(LOADING);   
		 url = '../tally/flow_categoryListQry.php?';
		 if (Flow.pg.params && !Flow.pg.flag) {url +=Flow.pg.params;}
		 submitSearch('flowSchForm',url+rnd(),'dataView',function(){
			 Flow.pg.query = Flow.searchByCategory; 
			 Flow.pg.init();  
		 });
	}
	
	Flow.exportByAccount = function(){
		 submitExport('flowSchForm',ctx+'/tally/flow_exportByAccount.php?'+rnd());
	}
	
	Flow.exportByCategory = function(){
		 submitExport('flowSchForm',ctx+'/tally/flow_exportByCategory.php?'+rnd());
	}
	
	Flow.goAddWeibo = function(cateSubjectName,amount,currencyType,activity,tradeTime,remark){
		
		var dtStr = tradeTime;
		var dtArr = dtStr.split(" ");
	  
		var date= new Date(Date.parse(dtArr[0].replace(/-/g,   "/"))); //转换成Data();  
  		var month = date.getMonth()+1;
  		  
  		 var content = "#财友晒账#"+ date.getFullYear()+"年"+month+"月"+date.getDate()+"日,我在"+
  		$.trim(cateSubjectName)+"上"+activity+"了"+amount+currencyType+"_";
  		 if(remark!=null&&remark!=''){
  			 content = content + "<"+remark+">";
  		 }
  		if (content.length>140){
  			content = content.substring(0,136)+'...>';
	      }
  		 Club.goAddWeibo (content);
	}
	
	
	/**************************装修*****************************/
	
	function Deco(){}
	Deco.pg = new Page('listtb');//列表页面
	
	Deco.search = function(){
		 $('#dataView').html(LOADING);
		 url = '../tally/expense.php?method=decoListQry';
		 if (Deco.pg.params) {url +=Deco.pg.params;}
         submitSearch('decoSchForm',url+rnd(),'dataView',function(){
        	 Deco.pg.init();
         });
	}
	
	Deco.pg.query = Deco.search;
	
	Deco.opener ='';
	
	Deco.pickDecoCate = function (me){
		var cateGroup = $(me).find("option:selected").val();
		
			Deco.opener = me;
			if(cateGroup==''){
				$('#decoCateId').empty();
				$('#decoCateId').addClass($('select:last').attr('class')); //IE 下select的class需要重新加载
				$('#decoCateId').append("<option value=''>请选择 </option>");
				return;
			}
			Deco.pickDeco(cateGroup);
	
	
	}
	
	Deco.onDelete = function (oid){
		deleteRow('../tally/home_delete.php?oid='+oid+rnd(),function(){
			Deco.search();	
       });
		
	}
	
	Deco.pickDeco = function (cateGroup){
				$.getJSON(ctx+"/tally/expense.php?method=getDecoCateOption"+rnd(),{'cateGroup':cateGroup},function(data){  
					  if (data.returnCode=='2'){
						  var dataObj=eval(data.data);
						  var options = '';
							$.each(dataObj,function(a,b){
								options=options+'<option value='+b.decoCateId+'>'+b.cateName+'</option>';
							})
							
						     
							$('#decoCateId').empty();
							$('#decoCateId').addClass($('select:last').attr('class')); //IE 下select的class需要重新加载
							$('#decoCateId').append(options);
							
							
					  }
				})
			}

	Deco.doDecoAdd = function (me){
		 Tally.validatePayee(me,1,function(){
	       submitSave('addForm','../tally/expense.php?method=doDecoAdd'+rnd(),function(data){
	     	  if($(me).val()=='保存'){
	        	  CM.close(me);
	        	  CM.afterSubmit0();
		    	  CM.afterSubmit();
	        	   
	    	  }else {
	    		  $('#amount').val('');
	    		  CM.afterSubmit0();
		    	  CM.afterSubmit();
	    	  }
	       })
	      });
	}
     
	Deco.list = function(){ 
        $('#main').load('../tally/expense.php?method=decoList'+rnd(),'',function(){  
           Help.show(1109,0);
           Deco.search();
        });
    }
	
    Deco.doDecoEdit =function(me){
	   Tally.validatePayee(me,1,function(){
	      submitSave('editForm','../tally/expense.php?method=doDecoEdit'+rnd(),function(data){    
	   		CM.close(me);
	   	    CM.afterSubmit0();
   	        CM.afterSubmit();
	      })
	      }); 
     }
	  
    Deco.exportExcel= function(){
		   submitExport('decoSchForm',ctx+'/tally/expense.php?method=doExport'+rnd());
	  }
		
    Deco.addDecoCate = function(me){
	  var cateGroup = $(me).find("option:selected").val(); 
	 
	  if(cateGroup=='add'){ 
		  Budget.goAdd('1');
	  } 
    }
	   
	   Deco.goEdit=function(oid,actionType,bizType,isCopyFlag){
	    var title = "";
	    var url = "";
	    var showCode ="";
	    title="支出";
	    url = "../tally/expense.php?method=edit&";
	    if(isCopyFlag=='0'){ showCode = 1043;}
	    if(isCopyFlag=='1'){ showCode = 1075;}
	     
	     if(url!=""){
	    	 if(isCopyFlag!='1') title = "修改"+title;
	    	 url = url+'oid='+oid+'&bizType='+bizType+'&isCopyFlag='+isCopyFlag+rnd();
		    	 CM.open(url,{title:title},function(){
			        Help.show(showCode,1);
			       
			     });
	     }	
   }

    
/**************************不同类型的账户列表*****************************/
	
	//现金
	Cash = function(){}
	Cash.pg = new Page('listtb');
	Cash.list = function(accountId){
		Cash.pg.params = '';
		$('#main').load('../tally/cash_list.php?subjectId='+accountId+rnd(),function(){  
			Cash.search();
		});
	}
	
	Cash.search = function(){
		 $('#dataView').html(LOADING);
		 url = '../tally/cash_listQry.php?';
		 if (Cash.pg.params) {url +=Cash.pg.params;}
         submitSearch('schForm',url+rnd(),'dataView',function(){
       	  Cash.pg.query = Cash.search; 
       	  Cash.pg.init();
         });
	}
	
	Cash.onExport = function() {
		 submitExport('schForm',ctx+'/tally/cash_onExport.php?'+rnd());
	}
	
	//储蓄
	Saving = function(){} 
	
	Saving.list = function(accountId){ //与现金一样，暂时不单写一个类
		Cash.pg.params = '';
		Cash.list(accountId);
	}
	
	//待摊费用
	Amortize = function(){}
	
	Amortize.list = function(accountId){ //与现金一样，保持一致
		Cash.pg.params = '';
		Cash.list(accountId);
	}
	
	//债权债务
	CreditDebt = function(){}
	CreditDebt.pg = new Page('listtb');
	
	CreditDebt.list = function(accountId){
		Help.show(1107,0);
		CreditDebt.pg.params = '';
		$('#main').load('../tally/creditDebt_list.php?subjectId='+accountId+rnd(),function(){  
			CreditDebt.search();
		});
	}
	
	CreditDebt.search = function(){
		 $('#dataView').html(LOADING);
		 url = '../tally/creditDebt_listQry.php?';
		 if (CreditDebt.pg.params) {url +=CreditDebt.pg.params;}
         submitSearch('schForm',url+rnd(),'dataView',function(){
        	 CreditDebt.pg.query = CreditDebt.search; 
        	 CreditDebt.pg.init();
         });
	}
	
	CreditDebt.summryList = function(accountId){
		CreditDebt.pg.params = '';
		$('#main').load('../tally/creditDebt_summryList.php?subjectId='+accountId+rnd(),function(){  
			CreditDebt.summrySearch();
		});
	}
	
	CreditDebt.summrySearch = function(){
		 $('#dataView').html(LOADING);
		 url = '../tally/creditDebt_summryListQry.php?';
		 if (CreditDebt.pg.params) {url +=CreditDebt.pg.params;}
        submitSearch('schForm',url+rnd(),'dataView',function(){
       	 	CreditDebt.pg.query = CreditDebt.summrySearch; 
       	 	CreditDebt.pg.init();
        });
	}
	
	CreditDebt.allList = function(accountId,payeeId){
		CreditDebt.pg.params = '';
		$('#main').load('../tally/creditDebt_allList.php?subjectId='+accountId+'&payeeId='+payeeId+rnd(),function(){  
			CreditDebt.allSearch();
		});
	}
	
	CreditDebt.allSearch = function(){
		 $('#dataView').html(LOADING);
		 url = '../tally/creditDebt_allListQry.php?';
		 if (CreditDebt.pg.params) {url +=CreditDebt.pg.params;}
        submitSearch('schForm',url+rnd(),'dataView',function(){
       	 	CreditDebt.pg.query = CreditDebt.allSearch; 
       	 	CreditDebt.pg.init();
        });
	}
	
	CreditDebt.exportAllList = function(){
		submitExport('schForm',ctx+'/tally/creditDebt_exportCreditDebtAll.php');
	}
	
	CreditDebt.exportList = function(){
		submitExport('schForm',ctx+'/tally/creditDebt_exportCreditDebt.php');
	}
	
	CreditDebt.exportSummryList = function(){
		submitExport('schForm',ctx+'/tally/creditDebt_exportCreditDebtSummry.php');
	}
	
	//销账
	CreditDebt.editPaidAmount = function(oid){
		CM.open('../tally/creditDebt_editPaidAmount.php?entryId='+oid+rnd(),{title:'销账',size:WINDOW_M},function(){
  		  Help.show(1106,1);
 	    });
	}
	
	CreditDebt.doEditPaidAmount = function(me){
		submitSave('editForm','../tally/creditDebt_doEditPaidAmount.php?'+rnd(),function(data){    
	   		CM.close(me);
	   		CM.afterSubmit();
	      });
	}
	
	CreditDebt.show = function(me){
		var list = $(me).parents('div.list_line:first').find('tr.sub_list');
		list.toggle();
	}
	
	
	//信用卡
	Credit = function(){}
	Credit.pg = new Page('listtb');
	
	Credit.list = function(accountId){
		Credit.pg.params = '';
		$('#main').load('../tally/credit_list.php?subjectId='+accountId+rnd(),function(){  
			Credit.search();
		});
	}
	
	Credit.search = function(){
		 $('#dataView').html(LOADING);
		 url = '../tally/credit_listQry.php?';
		 if (Credit.pg.params) {url +=Credit.pg.params;}
         submitSearch('schForm',url+rnd(),'dataView',function(){
        	 Credit.pg.query = Credit.search; 
        	 Credit.pg.init();
         });
	}
	Credit.orderList = function(accountId){
		Credit.pg.params = '';
		$('#main').load('../tally/credit_orderList.php?subjectId='+accountId+rnd(),function(){  
			Credit.orderSearch(accountId);
		});
	}
	Credit.orderSearch = function(){
 		$('#dataView').html(LOADING);
 		url = '../tally/credit_orderListQry.php?';
 			
 		submitSearch('schForm',url+rnd(),'dataView',function(){
       	 
        });
	}
	 
/***************************支出*****************************/
	Expense  = function(){};
	
	//打开新增支出页面
	Expense.goAdd=function(biz,subjectId){
		switch(biz){  
	     //根据业务行为biz来判断打开相应的记账页面
	     case '20':
	    	  CM.open('../tally/expense.php?method=add&bizType='+biz+"&subjectId="+subjectId+rnd(),{title:'支出',size:WINDOW_L},function(){
	    		  Help.show(1005,1);
	   	      });
	      		break;
	      case '21':
	    	  CM.open('../tally/expense.php?method=add&bizType='+biz+rnd(),{title:'赊欠的支出',size:WINDOW_L},function(){
	    		  //Help.show(1025,1);
	    	   });
	      		break;
	      case '22':
	    	  CM.open('../tally/expense.php?method=add&bizType='+biz+rnd(),{title:'资产贬值',size:WINDOW_L},function(){
	    		  Help.show(1025,1);
	    	   });
	      		break;
	      case '23':
	    	  CM.open('../tally/expense.php?method=add&bizType='+biz+rnd(),{title:'坏账支出',size:WINDOW_G},function(){
	    		  Help.show(1018,1);
	    	   });
	      		break;
	      case '24':
	    	  CM.open('../tally/expense.php?method=add&bizType='+biz+rnd(),{title:'装修支出',size:WINDOW_L},function(){
	    		  Help.show(1108,1);
	    	   });
	      		break;		
	      		
	 
	      default:
	            CM.alert('无法打开此记账页面！');	
	      		break;
	   }    
       
    }
	
	Expense.doDecoAdd = function (me){
		 Tally.validatePayee(me,1,function(){
	       submitSave('addForm','../tally/expense.php?method=doDecoAdd'+rnd(),function(data){
	     	  if($(me).val()=='保存'){
	        	  CM.close(me);
	    		  CM.afterSubmit0();
		    	  CM.afterSubmit();
	    	  }else {
	    		  $('#amount').val('');
	    		  CM.afterSubmit0();
		    	  CM.afterSubmit();
		    	  
	    		  //$('#expenseAdd_payeeId').find('option:first').attr('selected',true);
	    	  }
	       })
	      });
	}
	
	Expense.doAdd = function(me){
		 Tally.validatePayee(me,1,function(){
	       submitSave('addForm','../tally/expense.php?method=doAdd'+rnd(),function(data){
	     	  if($(me).val()=='保存'){
	        	  CM.close(me);
		    	  CM.afterSubmit0();
		    	  CM.afterSubmit();
	    	  }else {
	    		  $('#amount').val('');
	    		  $('#tagName').val('');
	    		  CM.afterSubmit0();
		    	  CM.afterSubmit();
	    		  //$('#expenseAdd_payeeId').find('option:first').attr('selected',true);
	    	  }
	       })
	      });
	   }
	
  
	Expense.doWeiboAdd = function (me){
		 Tally.validatePayee(me,1,function(){
		       submitSave('addForm','../tally/expense.php?method=doAdd'+rnd(),function(data){
		    	 var cateSubjectName =  $('div.content #subjectId1').find("option:selected").text();
		  	     var amount =  $('div.content #amount').val();
		  		 var bizType = $('div.content input[name=bizType]').val();
		  		 var activity = $('div.content input[name=activity]').val();
		  		 var remark = $('div.content #remark').val();
		  		 var tradeTime = $('div.content #tradeTime').val();
		  		 var subjectId = $('div.content #subjectId0').find("option:selected").val();
		  		 
		  		 

				   $.ajax({url:'api/club_getCurrencyName.php?subjectId='+subjectId,
			           type:"get",
			           dataType:"json",	           
			           success:function(data){
					   
					   var currencyName = data.currencyName;//币种名称
					   var date= new Date(Date.parse(tradeTime.replace(/-/g,   "/"))); //转换成Data();  
				  	   var month = date.getMonth()+1;
				  		  
				  	   var content = "#财友晒账#"+ date.getFullYear()+"年"+month+"月"+date.getDate()+"日,我在"+
				  		              $.trim(cateSubjectName)+"上"+activity+"了"+amount+currencyName+"_";
				  	   if(remark!=null&&remark!=''){
				  			 content = content + "<"+remark+">";
				  		 }
				  	   if (content.length>140){
				  			content = content.substring(0,136)+'...>';
					      }
				  	   Club.goAddWeibo (content);
					   
				      }
			       });
			   
		         
		        CM.close(me);
			    CM.afterSubmit0();
			    CM.afterSubmit();
			   
		       })
		  });
		 
	}
	
	
   Expense.doEdit =function(me){
	   Tally.validatePayee(me,1,function(){
	      submitSave('editForm','../tally/expense.php?method=doEdit'+rnd(),function(data){    
	   		CM.close(me);
	   		CM.afterSubmit0();
	   		CM.afterSubmit();
	      })
	      }); 
    }
   
   Expense.loadVoucherByPayee = function(me){
	   if($(me).val()=='add'){
		   return;
	   }
	   var relatedTallyContent = $('div.content #related_tally').html();
	   if(relatedTallyContent=='' || relatedTallyContent==null || relatedTallyContent==undefined){
		   return;
	   }
	   var payeeId = $('div.content select[name=payeeId]').val();
	   var subjectId = $('div.content select[name=subjectId0]').val();
	   //if(subjectId==undefined) subjectId=null;
	   $('#related_tally').load('../tally/expense.php?method=loadRelatedVoucher&payeeId='+payeeId+"&subjectId="+subjectId+rnd(),'',function(){
		   if($('div.content input[name=amount]').attr('readonly')){
			   $('div.content input[name=amount]').removeAttr('readonly');
			   $('div.content input[name=amount]').css('background-color','#ffffff');
		   }
		   var totalAmount = $('div.content input[name=totalAmount]').val();
		   if(totalAmount!=null && totalAmount!=0){
			   $('div.content input[name=amount]').attr('readonly','readonly');
			   $('div.content input[name=amount]').css('background-color','#d0d0d0');
		   }
	   });
   }
   
   Expense.loadRelatedVoucher = function(me){
	   $(me).hide();
	   $('div.content #hide_related_voucher').show();
	   var payeeId = $('div.content select[name=payeeId]').val();
	   var subjectId = $('div.content select[name=subjectId0]').val();
	   $('#related_tally').load('../tally/expense.php?method=loadRelatedVoucher&payeeId='+payeeId+"&subjectId="+subjectId+rnd(),'',function(){
		   var totalAmount = $('div.content input[name=totalAmount]').val();
		   if(totalAmount!=null && totalAmount!=0){
			   $('div.content input[name=amount]').attr('readonly','readonly');
			   $('div.content input[name=amount]').css('background-color','#d0d0d0');
		   }
	   });
   }
   
   /*************************收入*****************************/
   function Income(){} 
  
   Income.search = function(){};

   Income.goAdd = function(biz,subjectId){
	   switch(biz){  
	     //根据业务行为biz来判断打开相应的记账页面
	     case '11':
	  	   		CM.open('../tally/income.php?method=add&bizType='+biz+"&subjectId="+subjectId+rnd(),{title:'收入',size:WINDOW_L},function(){
	  	   		    Help.show(1002,1);
	  	   		});
	      		break;
	      case '12':
	    	  	CM.open('../tally/income.php?method=add&bizType='+biz+rnd(),{title:'拖欠的收入',size:WINDOW_L},function(){
	    	  		Help.show(1003,1);
	    	  	});
	      		break;
	      case '13':
	    	  	CM.open('../tally/income.php?method=add&bizType='+biz+rnd(),{title:'资产升值',size:WINDOW_L},function(){
	    	  		Help.show(1024,1);
	    	  	});
	      		break;
	      case '14':
	    	  	CM.open('../tally/income.php?method=add&bizType='+biz+rnd(),{title:'分红',size:WINDOW_L},function(){
	    	  		Help.show(1004,1);
	    	  	});
	      		break;
	      case '15':
	    	  	CM.open('../tally/income.php?method=add&bizType='+biz+rnd(),{title:'坏账收入',size:WINDOW_G},function(){
	    	  		Help.show(1021,1);
	    	  	});
	      		break;
	 
	      default:
	            CM.alert('无法打开此记账页面！');	
	      		break;
	   }    
   }
   
   Income.doAdd = function(me){
	   Tally.validatePayee(me,1,function(){
		   submitSave('addForm','../tally/income.php?method=doAdd'+rnd(),function(data){ 
		    	  if($(me).val()=='保存' && data.returnCode!='1'){
		        	  CM.close(me);
		        	  CM.afterSubmit0();
		    	   	  CM.afterSubmit();
		    	  }else {
		    		  $('#amount').val('');
		    		  CM.afterSubmit0();
		    	   	  CM.afterSubmit();
		    	  }
		      });
	   });
	   
       
   }
   
   
   Income.doWeiboAdd = function (me){
		 Tally.validatePayee(me,1,function(){
		       submitSave('addForm','../tally/income.php?method=doAdd'+rnd(),function(data){
		    	 var cateSubjectName =  $('div.content #subjectId1').find("option:selected").text();
		  	     var amount =  $('div.content #amount').val();
		  		 var bizType = $('div.content input[name=bizType]').val();
		  		 var activity = $('div.content input[name=activity]').val();
		  		 var remark = $('div.content #remark').val();
		  		 var tradeTime = $('div.content #tradeTime').val();
		  		 var subjectId = $('div.content #subjectId0').find("option:selected").val();
		  		 
				   $.ajax({url:'api/club_getCurrencyName.php?subjectId='+subjectId,
			           type:"get",
			           dataType:"json",	           
			           success:function(data){
					   
					   var  currencyName = data.currencyName;//币种名称
					   var date= new Date(Date.parse(tradeTime.replace(/-/g,   "/"))); //转换成Data();  
				  	   var month = date.getMonth()+1;
				  		  
				  	   var content = "#财友晒账#"+ date.getFullYear()+"年"+month+"月"+date.getDate()+"日,我在"+
				  		              $.trim(cateSubjectName)+"上"+activity+"了"+amount+currencyName+"_";
				       if(remark!=null&&remark!=''){
				  			 content = content + "<"+remark+">";
				  		 }
				       if (content.length>140){
				  			content = content.substring(0,136)+'...>';
					      }
				       Club.goAddWeibo (content);
					   
				     }
			       });
		  		   
		        CM.close(me);
			    CM.afterSubmit0();
			    CM.afterSubmit();
			   
		       })
		  });
		 
	}
   
    
 
   Income.doEdit =function(me){
	   Tally.validatePayee(me,1,function(){
	      submitSave('editForm','../tally/income.php?method=doEdit'+rnd(),function(data){ 
		    	if(data.returnCode!='1'){
			  	   	CM.close(me);
				   	CM.afterSubmit0();
				   	CM.afterSubmit();
			    }
	      })
	      }); 
   }
   
   Income.loadVoucherByPayee = function(me){
	   if($(me).val()=='add'){
		   return;
	   }
	   var relatedTallyContent = $('div.content #related_tally').html();
	   if(relatedTallyContent=='' || relatedTallyContent==null || relatedTallyContent==undefined){
		   return;
	   }
	   var payeeId = $('div.content select[name=payeeId]').val();
	   var subjectId = $('div.content select[name=subjectId0]').val();
	   //if(subjectId==undefined) subjectId=null;
	   $('#related_tally').load('../tally/income.php?method=loadRelatedVoucher&payeeId='+payeeId+"&subjectId="+subjectId+rnd(),'',function(){
		   if($('div.content input[name=amount]').attr('readonly')){
			   $('div.content input[name=amount]').removeAttr('readonly');
			   $('div.content input[name=amount]').css('background-color','#ffffff');
		   }
		   var totalAmount = $('div.content input[name=totalAmount]').val();
		   if(totalAmount!=null && totalAmount!=0){
			   $('div.content input[name=amount]').attr('readonly','readonly');
			   $('div.content input[name=amount]').css('background-color','#d0d0d0');
		   }
	   });
   }
   
   Income.loadRelatedVoucher = function(me){
	   $(me).hide();
	   $('div.content #hide_related_voucher').show();
	   var payeeId = $('div.content select[name=payeeId]').val();
	   var subjectId = $('div.content select[name=subjectId0]').val();
	   //if(subjectId==undefined) subjectId=null;
	   $('#related_tally').load('../tally/income.php?method=loadRelatedVoucher&payeeId='+payeeId+"&subjectId="+subjectId+rnd(),'',function(){
		   var totalAmount = $('div.content input[name=totalAmount]').val();
		   if(totalAmount!=null && totalAmount!=0){
			   $('div.content input[name=amount]').attr('readonly','readonly');
			   $('div.content input[name=amount]').css('background-color','#d0d0d0');
		   }
	   });
   }
   
/***********************待摊费用***************************/
   function Amortize(){}
   Amortize.goAdd = function(biz){
	   CM.open('../tally/amortize.php?method=add&bizType='+biz+rnd(),{title:'待摊费用',size:WINDOW_L},function(){
		   Help.show(1014,1);
	   });
   }
   
   Amortize.doAdd = function(me){
	   Tally.validatePayee(me,1,function(){
	   submitSave('addForm','../tally/amortize.php?method=doAdd'+rnd(),function(data){
	       if($(me).val()=='保存' && data.returnCode!='1'){
	    	   CM.close(me);
		       CM.afterSubmit0();
		   	   CM.afterSubmit();
	       }else {
	    		  $('#amount').val('');
	       }
	   	 });
	   });
   }
   Amortize.doEdit =function(me){
	  Tally.validatePayee(me,1,function(){
	  submitSave('editForm','../tally/amortize.php?method=doEdit'+rnd(),function(data){
		  if(data.returnCode!='1'){
			     CM.close(me);
			   	 CM.afterSubmit0();
			   	 CM.afterSubmit();	
		  }
	   	})
	  }); 
   }
   
/***********************资产变现（有盈亏的逻辑）*******************************/
   
   function AssertRealize(){}
   AssertRealize.goAdd = function(biz){
	   CM.open('../tally/assertRealize.php?method=add&bizType='+biz+rnd(),{title:'资产变现',size:WINDOW_L},function(){
		   Help.show(1023,1);
	   });
   }
   
   AssertRealize.doAdd = function(me){
	   Tally.validatePayee(me,1,function(){
	   submitSave('addForm','../tally/assertRealize.php?method=doAdd'+rnd(),function(data){
	       if($(me).val()=='保存' && data.returnCode!='1'){
	    	   CM.close(me);
		       CM.afterSubmit0();
		   	   CM.afterSubmit();
	       }else {
	    		  $('#amount').val('');
	       }
	   	 });
	   });
   }
   AssertRealize.doEdit =function(me){
	  Tally.validatePayee(me,1,function(){
	  submitSave('editForm','../tally/assertRealize.php?method=doEdit'+rnd(),function(data){
		  if(data.returnCode!='1'){
			     CM.close(me);
			   	 CM.afterSubmit0();
			   	 CM.afterSubmit();	
		  }
	   	})
	  }); 
   }
   
/*******************转账*******************/   
   function Transfer(){} 
   
   Transfer.goAdd = function(biz,subjectId){
	   switch   (biz){  
	     //根据业务行为biz来判断打开相应的记账页面
	     case '30':
	  	   		CM.open('../tally/transfer.php?method=add&bizType='+biz+"&subjectId="+subjectId+rnd(),{title:'转账',size:WINDOW_L},function(){
	  	   		  Help.show(1009,1);
	  	   		});
	      		break;
	      case '31':
	    	  	CM.open('../tally/transfer.php?method=add&bizType='+biz+rnd(),{title:'取钱',size:WINDOW_L},function(){
	    	  	  Help.show(1010,1);
	    	  	});
	      		break;
	      case '32':
	    	  	CM.open('../tally/transfer.php?method=add&bizType='+biz+rnd(),{title:'存钱',size:WINDOW_L},function(){
	    	  	  Help.show(1011,1);
	    	  	});
	      		break;
	      case '33':
	    	  	CM.open('../tally/transfer.php?method=add&bizType='+biz+rnd(),{title:'卡充值(公交卡、会员卡…)',size:WINDOW_L},function(){
	    	  	  Help.show(1013,1);
	    	  	});
	      		break;
	      case '34':
	    	  	CM.open('../tally/transfer.php?method=add&bizType='+biz+"&subjectId="+subjectId+rnd(),{title:'还信用卡',size:WINDOW_L},function(){
	    	  	  Help.show(1012,1);
	    	  	});
	      		break;
	      case '91':
	    	  	CM.open('../tally/transfer.php?method=add&bizType='+biz+rnd(),{title:'购置资产',size:WINDOW_L},function(){
	    	  	  Help.show(1022,1);
	    	  	});
	      		break;
	      case '92':
	    	  	CM.open('../tally/transfer.php?method=add&bizType='+biz+rnd(),{title:'资产变现',size:WINDOW_L},function(){
	    	  	  Help.show(1023,1);
	    	  	});
	      		break;
	      case '80':
	    	  	CM.open('../tally/transfer.php?method=add&bizType='+biz+rnd(),{title:'预收款',size:WINDOW_L},function(){
	    	  	 
	    	  	});
	      		break;
	      case '81':
	    	  	CM.open('../tally/transfer.php?method=add&bizType='+biz+rnd(),{title:'预付款',size:WINDOW_L},function(){
	    	  	
	    	  	});
	      		break;
	 
	      default:
	            CM.alert('无法打开此记账页面！');	
	      		break;
	   }
   }
   
   Transfer.doAdd = function(me){
	   Tally.validatePayee(me,2,function(){
       submitSave('addForm','../tally/transfer.php?method=doAdd'+rnd(),function(data){ 
    	  if($(me).val()=='保存' && data.returnCode!='1'){
        	  CM.close(me);
        	  CM.afterSubmit0();
    	   	  CM.afterSubmit();
    	  }else {
    		  $('#amount').val('');
    	  }
       })
      });
   }
   
   Transfer.doEdit = function(me){
	   Tally.validatePayee(me,2,function(){
	      submitSave('editForm','../tally/transfer.php?method=doEdit'+rnd(),function(data){
		    	if(data.returnCode!='1'){
			  	   	CM.close(me);
				   	CM.afterSubmit0();
				   	CM.afterSubmit();
			    }
	      })
	    });
   }
   
   
 /*********************Lend**************************/  
   function Lend(){};
   
   Lend.goAdd = function(biz){
	   switch   (biz){  
	     //根据业务行为biz来判断打开相应的记账页面
	     case '40':
	  	   		CM.open('../tally/lend.php?method=add&bizType='+biz+rnd(),{title:'借出款',size:WINDOW_L},function(){
	  	   		     Help.show(1016,1);
	  	   		});
	      		break;
	      case '41':
	    	  	CM.open('../tally/lend.php?method=add&bizType='+biz+rnd(),{title:'垫付',size:WINDOW_L},function(){
	    	  		Help.show(1007,1);
	    	  	});
	      		break;
	      case '42':
	    	  	CM.open('../tally/lend.php?method=add&bizType='+biz+rnd(),{title:'待报销的支出',size:WINDOW_L},function(){
	    	  		Help.show(1006,1);
	    	  	});
	      		break;
	      case '43':
	    	  	CM.open('../tally/lend.php?method=add&bizType='+biz+rnd(),{title:'交押金款',size:WINDOW_L},function(){
	    	  		Help.show(1008,1);
	    	  	});
	      		break;
	 
	      default:
	            CM.alert('无法打开此记账页面！');	
	      		break;
	   }    
   }

   Lend.doAdd = function (me){
	   Tally.validatePayee(me,2,function(){
	   submitSave('addForm','../tally/lend.php?method=doAdd'+rnd(),function(data){
	       if($(me).val()=='保存' && data.returnCode!='1'){
	          CM.close(me);
		      CM.afterSubmit0();
		   	  CM.afterSubmit();
	       }else {
	    		  $('#amount').val('');
	       }
	   })
	   });
	   
   }
   
   Lend.doEdit = function(me){
	    submitSave('editForm','../tally/lend.php?method=doEdit'+rnd(),function(data){
	    	if(data.returnCode!='1'){
		  	   	CM.close(me);
			   	CM.afterSubmit0();
			   	CM.afterSubmit();
		    }
	    });
   }
   
   
  /************************Borrow****************************/ 
   function Borrow(){};
   
   Borrow.goAdd = function(biz){
	    CM.open('../tally/borrow.php?method=add&bizType='+biz+rnd(),{title:'借入款',size:WINDOW_L},function(){
	    	Help.show(1019,1);
	   	});
   }

   Borrow.doAdd = function (me){
		
	   submitSave('addForm','../tally/borrow.php?method=doAdd'+rnd(),function(data){
	       if($(me).val()=='保存' && data.returnCode!='1'){
	          CM.close(me);
		      CM.afterSubmit0();
		   	  CM.afterSubmit();
	       }else {
	    	   $('#amount').val('');
	       }
	   });
	   
   }
   Borrow.doEdit = function(me){
	      submitSave('editForm','../tally/borrow.php?method=doEdit'+rnd(),function(data){
		    	if(data.returnCode!='1'){
			  	   	CM.close(me);
				   	CM.afterSubmit0();
				   	CM.afterSubmit();
			    }
	    });
   }
   
   /*************************TallyExchange:汇兑**************************************/
   function TallyExchange(){};
   
   TallyExchange.goAdd = function(biz){
	     //根据业务行为biz来判断打开相应的记账页面
	  	CM.open('../tally/exchange.php?method=add&bizType='+biz+rnd(),{title:'购汇结汇',size:WINDOW_L},function(){
	  		 var subjectId = $('#subjectId0').val();
	  		 if(subjectId!='' && subjectId!=null){
	  			 $('#exchangeRate').val(1);
	  		 }
	  		  Help.show(1015,1);
	  	});
   }
   
   TallyExchange.doAdd = function (me){
	   Tally.validatePayee(me,2,function(){
		   submitSave('addForm','../tally/exchange.php?method=doAdd'+rnd(),function(data){
		       if($(me).val()=='保存' && data.returnCode!='1'){
		          CM.close(me);
			      CM.afterSubmit0();
			   	  CM.afterSubmit();
		       }else {
		    	   $('#amount').val('');
		       }
		   })
	   });
	   
   }
   
   //汇兑的计算
   TallyExchange.doCalculate = function(){
	   //CM.alert($('#amountOut').val());
	   var amountOut = $('#amountOut').val();
	   var amountIn = $('#amountIn').val();
	   var exchangeRate = $('#exchangeRate').val();
	   //CM.alert(amountOut+'='+amountIn+'='+exchangeRate);
	   
   }
   
   TallyExchange.doEdit = function(me){
	   Tally.validatePayee(me,2,function(){
	      submitSave('editForm','../tally/exchange.php?method=doEdit'+rnd(),function(data){
	    	  if(data.returnCode!='1'){
	  	   		CM.close(me);
		   		CM.afterSubmit0();
		   		CM.afterSubmit();
	    	  }
	   	})
	    });
   }
   
   /******************************Payment**********************************/
   function Payment(){};
   
   Payment.goAdd = function(biz){
	     //根据业务行为biz来判断打开相应的记账页面
	  	CM.open('../tally/payment.php?method=add&bizType='+biz+rnd(),{title:'还钱',size:WINDOW_G},function(){
	  	  Help.show(1020,1);
	  	});
   }
   
   Payment.doAdd = function (me){
	  
	   submitSave('addForm','../tally/payment.php?method=doAdd'+rnd(),function(data){
	       if($(me).val()=='保存' && data.returnCode!='1'){
	          CM.close(me);
			  CM.afterSubmit0();	
			  CM.afterSubmit();
	       }else {
	    	  $('#amount').val('');
	       }	
	   });
   }
   
   Payment.doEdit = function(me){
	      submitSave('editForm','../tally/payment.php?method=doEdit'+rnd(),function(data){    
	    	  if(data.returnCode!='1'){
	  	   		CM.close(me);
		   		CM.afterSubmit0();
		   		CM.afterSubmit();	
	    	  }
	    });
   }
   
   Payment.loadVoucherByPayee = function(me){
	   if($(me).val()=='add'){
		   return;
	   }
	   var relatedTallyContent = $('div.content #related_tally').html();
	   //CM.alert(relatedTallyContent);
	   if(relatedTallyContent==null || relatedTallyContent==undefined || relatedTallyContent.trim()==''){
		   return;
	   }
	   var payeeId = $('div.content select[name=payeeId]').val();
	   var subjectId = $('div.content select[name=subjectId1]').val();
	   if(subjectId==undefined) subjectId=null;
	   $('#related_tally').load('../tally/payment.php?method=loadRelatedVoucher&payeeId='+payeeId+"&subjectId="+subjectId+rnd(),'',function(){
		   /*CM.alert($('div.content input[name=amount]'));*/
		   //CM.alert($('div.content input[name=amount]').attr('readonly'));
		   if($('div.content input[name=amount]').attr('readonly')){
			   $('div.content input[name=amount]').removeAttr('readonly');
			   $('div.content input[name=amount]').css('background-color','#ffffff');
		   }
		   var totalAmount = $('div.content input[name=totalAmount]').val();
		   //$('div.content input[name=amount]').val(totalAmount);
		   if(totalAmount!=null && totalAmount!=0){
			   $('div.content input[name=amount]').attr('readonly','readonly');
			   $('div.content input[name=amount]').css('background-color','#d0d0d0');
		   }
	   });
   }
   
   Payment.loadRelatedVoucher = function(me){
	   /*CM.alert($(me).parent('#content').find('#related_tally'));
	   $(me).parent('#content').find('#related_tally').show();*/
	   /*$('#related_tally').show();
	   $(me).text('取消关联»');*/
	   $(me).hide();
	   $('div.content #hide_related_voucher').show();
	   var payeeId = $('div.content select[name=payeeId]').val();
	   var subjectId = $('div.content select[name=subjectId1]').val();
	   if(subjectId==undefined) subjectId=null;
	   $('#related_tally').load('../tally/payment.php?method=loadRelatedVoucher&payeeId='+payeeId+"&subjectId="+subjectId+rnd(),'',function(){
		   /*CM.alert($('div.content input[name=amount]'));*/
		   var totalAmount = $('div.content input[name=totalAmount]').val();
		   //$('div.content input[name=amount]').val(totalAmount);
		   if(totalAmount!=null && totalAmount!=0){
			   $('div.content input[name=amount]').attr('readonly','readonly');
			   $('div.content input[name=amount]').css('background-color','#d0d0d0');
		   }
	   });
   }
   
   /******************************Receipt**********************************/
   function Receipt(){};
   
   Receipt.goAdd = function(biz){
	     //根据业务行为biz来判断打开相应的记账页面
	  	CM.open('../tally/receipt.php?method=add&bizType='+biz+rnd(),{title:'收钱',size:WINDOW_G},function(){
	  	  Help.show(1017,1);
	  	});
   }
   
   Receipt.doAdd = function(me){
	   submitSave('addForm','../tally/receipt.php?method=doAdd'+rnd(),function(data){
	       if($(me).val()=='保存' && data.returnCode!='1'){
	          CM.close(me);
			  CM.afterSubmit0();
			  CM.afterSubmit();
	       }else {
	    	  $('#amount').val('');
	       }
	   });
   }
   
   Receipt.doEdit = function(me){
	   	//alert('doEdit');
	      submitSave('editForm','../tally/receipt.php?method=doEdit'+rnd(),function(data){    	 
	    	  if(data.returnCode!='1'){
		  	   		CM.close(me);
			   		CM.afterSubmit0();
			   		CM.afterSubmit();	
	    	  }
	    });
   }
   
   Receipt.loadVoucherByPayee = function(me){
	   if($(me).val()=='add'){
		   return;
	   }
	   var relatedTallyContent = $('div.content #related_tally').html();
	   if(relatedTallyContent==null || relatedTallyContent==undefined || relatedTallyContent.trim()==''){
		   return;
	   }
	   var payeeId = $('div.content select[name=payeeId]').val();
	   var subjectId = $('div.content select[name=subjectId1]').val();
	   if(subjectId==undefined) subjectId=null;
	   $('#related_tally').load('../tally/receipt.php?method=loadRelatedVoucher&payeeId='+payeeId+"&subjectId="+subjectId+rnd(),'',function(){
		   /*CM.alert($('div.content input[name=amount]'));*/
		   //CM.alert($('div.content input[name=amount]').attr('readonly'));
		   if($('div.content input[name=amount]').attr('readonly')){
			   $('div.content input[name=amount]').removeAttr('readonly');
			   $('div.content input[name=amount]').css('background-color','#ffffff');
		   }
		   var totalAmount = $('div.content input[name=totalAmount]').val();
		   //$('div.content input[name=amount]').val(totalAmount);
		   if(totalAmount!=null && totalAmount!=0){
			   $('div.content input[name=amount]').attr('readonly','readonly');
			   $('div.content input[name=amount]').css('background-color','#d0d0d0');
		   }
	   });
   }
   
   Receipt.loadRelatedVoucher = function(me){
	   /*CM.alert($(me).parent('#content').find('#related_tally'));
	   $(me).parent('#content').find('#related_tally').show();*/
	   /*$('#related_tally').show();
	   $(me).text('取消关联»');*/
	   $(me).hide();
	   $('div.content #hide_related_voucher').show();
	   var payeeId = $('div.content select[name=payeeId]').val();
	   var subjectId = $('div.content select[name=subjectId1]').val();
	   if(subjectId==undefined) subjectId=null;
	   $('#related_tally').load('../tally/receipt.php?method=loadRelatedVoucher&payeeId='+payeeId+"&subjectId="+subjectId+rnd(),'',function(){
		   /*CM.alert($('div.content input[name=amount]'));*/
		   var totalAmount = $('div.content input[name=totalAmount]').val();
		   //$('div.content input[name=amount]').val(totalAmount);
		   if(totalAmount!=null && totalAmount!=0){
			   $('div.content input[name=amount]').attr('readonly','readonly');
			   $('div.content input[name=amount]').css('background-color','#d0d0d0');
		   }
	   });
   }
/******************************Cat6.1版本新增应收应付的相关功能************************************/
   function Arap(){}
   Arap.checkAmount =function(ele){
   	var chkAmount = $(ele).parent().parent().find('#chkAmount');	
       var paidAmount = $(ele).parent().parent().find('input[name^=paidAmount]:enabled');
       if(Number(ForDight(chkAmount.val(),2))<Number(paidAmount.val())){
       	paidAmount.val(ForDight(chkAmount.val(),2));
       	CM.alert("输入金额不能大于应还/付金额_");
       	return false;
       }else{
       	return true;
        }
   }
   //计算总的收款额
   Arap.calcTotalAmount=function(ele){
      if(_Arap.checkAmount(ele)){
   	 return false;
      }
      var theTable = $(ele).parent().parent().parent();
      var ob = theTable.find('input[name^=paidAmount]:enabled');//实收金额
      var total=0;
      ob.each(function(){
         total+=Number($(this).val());
      })
      theTable.find('#totalAmount').val(ForDight(total,2));
      $('div.content input[name=amount]').val(ForDight(total,2));
      var totalAmount = $('div.content input[name=totalAmount]').val();
	  if(totalAmount!=null && totalAmount!=0){
		  $('div.content input[name=amount]').attr('readonly','readonly');
		  $('div.content input[name=amount]').css('background-color','#d0d0d0');
	  }
   }
/**************************Stock********************************/
   function Stock(){}
   Stock.pg = new Page('listtb');//列表页面
   Stock.accountId='';
   
   Stock.list = function(accountId){
	   Stock.pg.params = '';
		$('#main').load('../tally/stock.php?method=list&subjectId='+accountId+rnd(),function(){  
			Stock.search();
		});
	}
   Stock.search = function(){
//		 $('#dataView').html(LOADING);
//		 url = '../tally/stock.php?method=listQry';
//		 if (Stock.pg.params) {url +=Stock.pg.params;}
//		 	submitSearch('schForm',url+rnd(),'dataView',function(){
//		 		Stock.pg.query = Stock.search; 
//		 		Stock.pg.init();
//        });
	   
	   Cash.search();
	   
	}
   
   Stock.tranList = function(accountId){
	   Stock.pg.params = '';
		$('#main').load('../tally/stock.php?method=tranList&subjectId='+accountId+rnd(),function(){  
			Stock.tranSearch();
		});
	}
   Stock.tranSearch = function(){
		 $('#dataView').html(LOADING);
		 url = '../tally/stock.php?method=tranListQry';
		 if (Stock.pg.params) {url +=Stock.pg.params;}
		 	submitSearch('schForm',url+rnd(),'dataView',function(){
		 		Stock.pg.query = Stock.search; 
		 		Stock.pg.init();
        });
	}
   
   Stock.summary = function(accountId){
	   Stock.pg.params = '';
		$('#main').load('../tally/stock.php?method=summaryList&subjectId='+accountId+rnd(),function(){  
			Stock.summarySearch();
		});
	}
   
   Stock.summarySearch = function(){
		 $('#dataView').html(LOADING);
		 url = '../tally/stock.php?method=summaryListQry';
		 if (Stock.pg.params) {url +=Stock.pg.params;}
		 	submitSearch('schForm',url+rnd(),'dataView',function(){
		 		Stock.pg.query = Stock.summarySearch; 
		 		Stock.pg.init();
        });
	}
	
	//证券买入总价
	Stock.calcAmount = function(me){
		var form=$(me).parents('form:first');
		var price=form.find('input[name=price]').val();//价格
		var quantity=form.find('input[name=quantity]').val(); //数量
		if(_isInteger(quantity)){
			CM.alert('数量必须为整数！');
			return;
		}
		if(_isNumber(price)){
			CM.alert('价格必须为数字！');
			return;
		}
		if(price&&quantity&&isNumber(price)&&isInteger(quantity)){ //数量和价格同时合法的时候才计算
			var amount = price*quantity;
			form.find('input[name=amount]').val(ForDight(amount,2));
		}
		
	     
	}
	
	//检查证券代码
	Stock.checkCode = function(){
		  var code = $('#stockCode').val();
	      if (_code) return;
	      var stockType = $('#stockType').val();
		  submitReq('../tally/buyStock.php?method=getStockByCode&stockCode='+code+'&stockType='+stockType+rnd(),function(data){
		       if (data.returnCode=='2'){
		    	  if(data.returnMsg){
		    		  $('#ckstock_msg').html(data.returnMsg);
		    		  //$("#stockCode").focus();
		    	  }else{
		    		  $('#ckstock_msg').html("证券名称:"+data.stockName);
		    	  }
		          return;
		       }
		  });
	}
	
	
	Stock.goAddBuy=function(biz,subjectId){
		CM.open('../tally/buyStock.php?method=add&bizType='+biz+'&subjectId='+subjectId+rnd(),{title:'买入证券',size:WINDOW_L},function(){
			  Help.show(1026,1);
 		});
    }
	
	Stock.doAddBuy = function(me){
		submitSave('addForm','../tally/buyStock.php?method=doAdd'+rnd(),function(data){
	       if($(me).val()=='保存' && data.returnCode!='1'){
		        CM.close(me);
		  		CM.afterSubmit0();
		   		CM.afterSubmit();
		   }else {
	    		$('#amount').val('');
		   }
		});
   }
   Stock.doEditBuy = function(me){
   		submitSave('editForm','../tally/buyStock.php?method=doEdit'+rnd(),function(data){ 	 
	    	  if(data.returnCode!='1'){
		  	   		CM.close(me);
			   		CM.afterSubmit0();
			   		CM.afterSubmit();	
	    	  }
        });
   }
	
	Stock.goAddSell=function(biz,subjectId){
		CM.open('../tally/sellStock.php?method=add&bizType='+biz+'&subjectId='+subjectId+rnd(),{title:'卖出证券',size:WINDOW_L},function(){
			  Help.show(1027,1);
 		});
   }
	
	Stock.doAddSell = function(me){
		submitSave('addForm','../tally/sellStock.php?method=doAdd'+rnd(),function(data){ 
	       if($(me).val()=='保存' && data.returnCode!='1'){
		        CM.close(me);
		  		CM.afterSubmit0();
		   		CM.afterSubmit();
		   }else {
	    		$('#amount').val('');
		   }
   		});
   }
	
	Stock.doEditSell = function(me){
		submitSave('editForm','../tally/sellStock.php?method=doEdit'+rnd(),function(data){ 
			if(data.returnCode!='1'){
	   			CM.close(me);
	   			if(CM.afterSubmit0){CM.afterSubmit0();}
	            CM.afterSubmit();
			}	
       });
    }
	
	Stock.goAddShare=function(biz){
	  	CM.open('../tally/shareStock.php?method=add&bizType='+biz+rnd(),{title:'配股',size:WINDOW_L},function(){
	  	  Help.show(1028,1); 
	  	});
    }
	
	Stock.doAddShare = function(me){
		submitSave('addForm','../tally/shareStock.php?method=doAdd'+rnd(),function(data){
	       if($(me).val()=='保存'){
		        CM.close(me);
				CM.afterSubmit0();
		   		CM.afterSubmit();
		   }else {
	    		$('#amount').val('');
		   }
		});
    }
	
	Stock.doEditShare = function(me){
		  submitSave('editForm','../tally/shareStock.php?method=doEdit'+rnd(),function(data){ 
				if(data.returnCode!='1'){
		   			CM.close(me);
		   			if(CM.afterSubmit0){CM.afterSubmit0();}
		            CM.afterSubmit();
				}		
	       });
	}
	
	Stock.goAddGive=function(biz){
	  	CM.open('../tally/giveStock.php?method=add&bizType='+biz+rnd(),{title:'送股',size:WINDOW_L},function(){
	  	  Help.show(1029,1);
	  	});
    }
	
	Stock.doAddGive = function(me){
		submitSave('addForm','../tally/giveStock.php?method=doAdd'+rnd(),function(data){
	       if($(me).val()=='保存'){
		        CM.close(me);
				CM.afterSubmit0();
		   		CM.afterSubmit();
		   }else {
	    		$('#amount').val('');
		   }
		});
    }
	
	Stock.exportStockTran = function(){
		submitExport('schForm',ctx+'/tally/stock.php?method=exportTran');
	}
	
/***************************Fund******************************/
	function Fund(){}
	Fund.pg = new Page('listtb');//列表页面
	Fund.accountId='';

	Fund.list = function(accountId){
		Fund.pg.params = '';
			$('#main').load('../tally/fund.php?method=list&subjectId='+accountId+rnd(),function(){  
				Fund.search();
		});
	}
	Fund.search = function(){
		Cash.search();
	}
	
	Fund.tranList = function(accountId){
		Fund.pg.params = '';
			$('#main').load('../tally/fund.php?method=tranList&subjectId='+accountId+rnd(),function(){  
				Fund.tranSearch();
		});
	}
	Fund.tranSearch = function(){
		$('#dataView').html(LOADING);
			 url = '../tally/fund.php?method=tranListQry';
			 if (Fund.pg.params) {url +=Fund.pg.params;}
			 submitSearch('schForm',url+rnd(),'dataView',function(){
				 Fund.pg.query = Fund.search; 
				 Fund.pg.init();
	    });
	}
	   
	Fund.summary = function(accountId){
		Fund.pg.params = '';
			$('#main').load('../tally/fund.php?method=summaryList&subjectId='+accountId+rnd(),function(){  
				Fund.summarySearch();
		});
	}
	   
	Fund.summarySearch = function(){
		$('#dataView').html(LOADING);
		url = '../tally/fund.php?method=summaryListQry';
		if (Fund.pg.params) {url +=Fund.pg.params;}
			 	submitSearch('schForm',url+rnd(),'dataView',function(){
			 		Fund.pg.query = Fund.summarySearch; 
			 		Fund.pg.init();
	    });
	}
	//计算买入总价
	Fund.calcAmount = function(me){
	//function calcBuyFundAmount
		var form=$(me).parents('form:first');
		var price=form.find('input[name=price]').val();//价格
		var quantity=form.find('input[name=quantity]').val(); //数量
		if(_isNumber(quantity)){
			CM.alert('份额必须为数字！');
			return;
		}
		if(_isNumber(price)){
			CM.alert('价格必须为数字！');
			return;
		}
		if(price&&quantity&&isNumber(price)&&isNumber(quantity)){ //数量和价格同时合法的时候才计算
			var amount = price*quantity;
			form.find('input[name=amount]').val(ForDight(amount,2));
		}
	}
	
	//检查基金代码
	Fund.checkCode = function(code){
	      if (_code) return;
		  submitReq('../tally/buyFund.php?method=getFundByCode&fundCode='+code+rnd(),function(data){
			  
			  if (data.returnCode=='2'){
		    	  if(data.returnMsg){
		    		  $('#fund_msg').html(data.returnMsg);
		    		  //$("#fundCode").focus();
		    	  }else{
		    		  $('#fund_msg').html("基金名称:"+data.fundName);
		    	  }
		          return;
		       }
		  });
	}

	
	Fund.goAddBuy=function(biz,subjectId){
		CM.open('../tally/buyFund.php?method=add&bizType='+biz+'&subjectId='+subjectId+rnd(),{title:'买入基金',size:WINDOW_L},function(){
			  Help.show(1030,1);
 		});
    }
	
	Fund.doAddBuy = function(me){
		var quantity = $('#quantity').val();
		var pattern = /(^[1-9]\d*(.[0-9]{1,4})?$)/;
		if(_pattern.test(quantity)){
			CM.alert('基金份额输入不正确,最多只能有4位小数！');
			return;
		}
		submitSave('addForm','../tally/buyFund.php?method=doAdd'+rnd(),function(data){
	       if($(me).val()=='保存' && data.returnCode!='1'){
		        CM.close(me);
		  		CM.afterSubmit0();
		   		CM.afterSubmit();
		   }else {
	    		  $('#amount').val('');
	    	  }
		});
    }
	
	Fund.doEditBuy = function(me){
		submitSave('editForm','../tally/buyFund.php?method=doEdit'+rnd(),function(data){ 
			if(data.returnCode!='1'){
	   			CM.close(me);
	   			CM.afterSubmit0();
	            CM.afterSubmit();	
			}
       });
		}
	
	Fund.goAddSell=function(biz,subjectId){
		CM.open('../tally/sellFund.php?method=add&bizType='+biz+'&subjectId='+subjectId+rnd(),{title:'卖出基金',size:WINDOW_L},function(){
			  Help.show(1031,1);
 		});
    }
	
	Fund.doAddSell = function(me){
		var quantity = $('#quantity').val();
		var pattern = /(^[1-9]\d*(.[0-9]{1,4})?$)/;
		if(_pattern.test(quantity)){
			CM.alert('基金份额输入不正确,最多只能有4位小数！');
			return;
		}
		submitSave('addForm','../tally/sellFund.php?method=doAdd'+rnd(),function(data){
		       if($(me).val()=='保存' && data.returnCode!='1'){
			        CM.close(me);
			  		CM.afterSubmit0();
			   		CM.afterSubmit();
			   }else {
		    		  $('#amount').val('');
		    	  }
		});
   }
	
	Fund.doEditSell = function(me){
		submitSave('editForm','../tally/sellFund.php?method=doEdit'+rnd(),function(data){ 
			if(data.returnCode!='1'){
	   			CM.close(me);
	   			CM.afterSubmit0();
	            CM.afterSubmit();	
			}
        });
   }

	Fund.goAddSplit=function(biz){
		CM.open('../tally/splitFund.php?method=add&bizType='+biz+rnd(),{title:'基金拆分',size:WINDOW_L},function(){
			  Help.show(1032,1);
 		});
   }
	
	Fund.doAddSplit = function(me){
		var quantity0 = $('#quantity0').val();
		var quantity1 = $('#quantity1').val();
		var pattern = /(^[1-9]\d*(.[0-9]{1,4})?$)/;
		if(_pattern.test(quantity0) || _pattern.test(quantity1)){
			CM.alert('基金份额输入不正确,最多只能有4位小数！');
			return;
		}
		submitSave('addForm','../tally/splitFund.php?method=doAdd'+rnd(),function(data){
		       if($(me).val()=='保存'){
			        CM.close(me);
			  		CM.afterSubmit0();
			   		CM.afterSubmit();
			   }else {
		    		  $('#amount').val('');
		    	  }
		});
   }

	Fund.goAddBonusInvest=function(biz){
		CM.open('../tally/bonusInvestFund.php?method=add&bizType='+biz+rnd(),{title:'分红再投资',size:WINDOW_L},function(){
			  Help.show(1033,1);
 		});
    }
	
	Fund.doAddBonusInvest = function(me){
		var quantity = $('#quantity').val();
		var pattern = /(^[1-9]\d*(.[0-9]{1,4})?$)/;
		if(_pattern.test(quantity)){
			CM.alert('基金份额输入不正确,最多只能有4位小数！');
			return;
		}
		submitSave('addForm','../tally/bonusInvestFund.php?method=doAdd'+rnd(),function(data){
		       if($(me).val()=='保存'){
			        CM.close(me);
			  		CM.afterSubmit0();
			   		CM.afterSubmit();
			   }else {
		    		  $('#amount').val('');
		    	  }
		});
   }
	
	Fund.doEditBonus = function(me){
		  submitSave('editForm','../tally/bonusInvestFund.php?method=doEdit'+rnd(),function(data){ 
	   			CM.close(me);
	   			if(CM.afterSubmit0){CM.afterSubmit0();}
	            CM.afterSubmit();	
	      });
	}

	//导出
	Fund.exportFundTran = function(){
		submitExport('schForm',ctx+'/tally/fund.php?method=exportTran');
	}
   
/************************Remind****************************/
  function Remind(){}
  Remind.pg = new Page('listtb');//列表页面

  //查询
  Remind.search = function(){
//     var zone = 'main_remind';
//     var form='schForm';
//     var action='../tally/remind_list.php?';    
//      url = action;
//      if (Remind.pg.params) {url +=Remind.pg.params;}
//      submitSearch(form,url+rnd(),zone,function(){Remind.pg.init();});            
  }       		
  Remind.pg.query = Remind.search;
  
  
  //打开新增提醒页面
  Remind.goAdd=function(){
//      CM.open('../tally/remind_add.php?'+rnd(),{title:'新增提醒',size:WINDOW_M},function(){
//      	Help.show(511,1);
//      });
  }

  //新增
  Remind.save = function(me){
//     submitSave('addForm','../tally/remind_doAdd.php?'+rnd(),function(){
//  		CM.close(me);
//  		Remind.search();
//     });
  }
  
  //打开修改页面
  Remind.goEdit=function(oid){
//      CM.open('../tally/remind_edit.php?oid='+oid+rnd(),{title:'修改提醒',size:WINDOW_M},function(){
//      	Help.show(512,1);
//      });
  }
             
  //修改
  Remind.update = function(me){   
//     submitSave('editForm','../tally/remind_doEdit.php?'+rnd(),function(){
//  		CM.close(me);
//  		Remind.search();
//     });      
  }

  //删除
  Remind.onDelete = function(oid){
//     deleteRow('../tally/remind_delete.php?oid='+oid+rnd(),function(){
//  		Remind.search();
//     });       
  }
    
  Remind.list = function(){
//      $('#main').load('../tally/remind_list.php?'+rnd(),'',function(){
//      	Help.show(510,0);
//         Remind.search();
//      });
  }      
  
  
  /******************批量记账*******************/
     
     function BatchTally(){}
     BatchTally.goAdd = function(){
  	   Help.show(1035);
  	   $('#main').load('../tally/batchTally_add.php?'+rnd(),function(){
  	   });
     }
     BatchTally.doAdd=function(me){
  	     submitSave('batchTallyForm','../tally/batchTally_doAdd.php?'+rnd(),function(data){ 
      	   if(data.returnCode!='1'){
      	  	   CM.afterSubmit0();
      	  	   CM.afterSubmit();
      	   }
  	     });
     }
     
     
     /******************从文件导入*******************/
     function ImportAccount(){}
     ImportAccount.goAdd = function(){
  	   Help.show(1036);
  	   $('#main').load('../tally/import.php?method=add&'+rnd(),function(){});
     }
	ImportAccount.doClear=function(){
		CM.confirm('温馨提示:将清除账本、标签、分类、收支转账记录。数据清除是不可逆的，您是否继续？',function(){
			submitSave('addForm',ctx+'/tally/clearData.php?'+rnd(),function(data){
				if(data.returnCode!='1'){
					Tally.loadBoard();
					Flow.listByAccount();
				}
			});
		});
	}
	ImportAccount.doAdd=function(){
		CM.confirm('温馨提示:数据导入是不可逆的，您是否继续？',function(){
			doImport();
		});
	}

	var doImport = function(continueImport){
		continueImport = continueImport?1:0;
		submitSave('addForm',ctx+'/tally/import.php?method=doAdd&'+'continue='+continueImport+'&'+rnd(),function(data){
			if(data.backgroundRunning=='1'){
				doImport(true);
			}else{
				Tally.loadBoard();
				Flow.listByAccount();
			}
		});
	};

	/*****************************自动记账************************************/
     Schedule = function() {
     }
     Schedule.pg = new Page('listtb');// 列表页面

     Schedule.list = function() {
     	$('#main').load('../tally/schedule.php?method=list' + rnd(), '',function() {
     		Help.show(1037, 0);
     		Schedule.search();
     	});
     }

     // 查询
     Schedule.search = function() {
     	var zone = 'dataView';
     	var form = 'schForm';
     	var action = '../tally/schedule.php?method=listQry';
     	url = action;
     	if (Schedule.pg.params) {
     		url += Schedule.pg.params;
     	}
     	$('#dataView').load(url + rnd(), '', function() {
     		Schedule.pg.init();
     	});
     }
     Schedule.pg.query = Schedule.search;

     // 打开新增自动记账页面
     Schedule.goAdd = function() {
     	var amount = $('#amount').val();
     	var subjectId0 = $('#subjectId0').val();
     	var subjectId1 = $('#subjectId1').val();
     	var payeeId = $('#payeeId').val();
     	var remark = $('#remark').val();
     	var tags = $('#tagName').val()==undefined?'':$('#tagName').val();
     	CM.open('../tally/schedule.php?method=add&amount='+amount+'&subjectId0='+subjectId0+'&subjectId1='
     			+subjectId1+'&payeeId='+payeeId+'&remark='+remark+'&tags='+tags+ rnd(), {
     		title :'新增自动记账',
     		size :WINDOW_G
     	}, function() {
     		Help.show(1038, 1);
     	});
     }

     // 新增
     Schedule.save = function(me) {
  	   Tally.validatePayee(me,1,function(){
     	submitSave('scheduleAddForm', '../tally/schedule.php?method=doAdd' + rnd(),function(data) {
     		if(data.returnCode!='1'){
         		CM.close(me);
         		Schedule.search();
     		}
     	});
  	   });
     }

     // 打开修改页面
     Schedule.goEdit = function(oid) {
     	CM.open('../tally/schedule.php?method=edit&oid=' + oid + rnd(), {
     		title :'修改自动记账',
     		size :WINDOW_G
     	}, function() {
     		Schedule.search();
     		Help.show(1039, 1);
     	});
     }

     // 修改
     Schedule.update = function(me) {
     	if ($("input[name='monthType'][checked]:radio").val() == '1') { // 月份
     		if (_$("input[name='monthNum'][checked]:checkbox").val()) {
     			CM.alert('设置自动记账月份有误！');
     			return;
     		}
     	}
     	// 天份
     	var dayType = $("input[name='dayType'][checked]:radio").val();
     	if (dayType == '0') {
     		var dayNum = $("#dayNum").val();
     		if (dayNum > 31 || dayNum < 1) {
     			CM.alert('设置自动记账天数必须在1~31之间');
     			return;
     		}
     	}
     	if (dayType == '3') {
     		if (_$("input[name='weekNum'][checked]:checkbox").val()) {
     			CM.alert('设置自动记账星期有误！');
     			return;
     		}
     	}
   	   Tally.validatePayee(me,1,function(){
     	submitSave('editForm', '../tally/schedule.php?method=doEdit' + rnd(),function(data){
     		if(data.returnCode!='1'){
 				CM.close(me);
 				Schedule.search();
     		}
     	});
   	   });
     }

     // 删除
     Schedule.onDelete = function(oid) {
     	deleteRow1('../tally/schedule.php?method=delete&scheduleId=' + oid
     			+ rnd(), "确定要删除吗？", function() {
     		Schedule.search();
     	});
     }

     // 启动
     Schedule.start = function(scheduleId) {
     	$.get('../tally/schedule.php?method=start&scheduleId'+ scheduleId + rnd(),
     		{scheduleId :scheduleId},function(data) {
     			document.getElementById(scheduleId).src = ctx + '/images/common/run.gif';
     			document.getElementById(scheduleId).title = '正在运行';
     	});
     }

     // 停止
     Schedule.stop = function(scheduleId) {
     	$.get('../tally/schedule.php?method=stop&scheduleId'+ scheduleId + rnd(),
     		{scheduleId :scheduleId},function(data) {
     			document.getElementById(scheduleId).src = ctx + '/images/common/stop.gif';
     			document.getElementById(scheduleId).title = '暂停运行';
     	});
     }

     // 执行
     Schedule.run = function(scheduleId) {
     	$.ajax( {
     		url :'../tally/schedule.php?method=run&scheduleId=' + scheduleId
     				+ rnd(),
     		type :"get",
     		dataType :"json",
     		// error:reportError,
     		success : function(data) {
	    	    Tally.loadBoard();
     			Schedule.search();
     		}
     	});
     }
   
   
   
  
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   /*******************特殊帐*******************/   
   function Special(){} 
   
   Special.goAdd = function(){
	   /*$('#tally_page').load('../tally/special.php?method=add'+rnd(),function(){
		   if($('#menu').text()!="其他账"){
			   $("#activity").val($('#menu').text());
		   }
	   });*/
	   CM.open('../tally/special.php?method=add'+rnd(),{title:'特殊帐',size:WINDOW_M},function(){
		   Help.show(4040,0);
	       });
   }
   Special.doAdd = function(){
	  // $('#subjectId').val('');//清除隐藏传值,以便充值subjectId条件
	   AutoTask.validate();
       submitSave('addForm','../tally/special.php?method=doAdd'+rnd(),function(data){ 
    	   Tally.clear();
    	   Tally.loadBoard();
    	   Entry.search();
      });
       CM.afterSubmit0();
  	   CM.afterSubmit();
   }
   Special.doEdit = function(me){
	      submitSave('editForm','../tally/special.php?method=doEdit'+rnd(),function(){    		
	   		CM.close(me);
	   		CM.afterSubmit0();
	   		CM.afterSubmit();	
	    });
   }
   /**********************entry查询*************************/
	 Entry= function(){}
	 Entry.pg = new Page("listtb");
	 //entry 明细查询
	 Entry.listByAccount = function(){
	  $('#main').load('../tally/entry_list.php?'+rnd(),'',function(){     
	        Entry.searchByAccount();
	   });
	 }
	 
	 Entry.listByCategory = function(){
		  $('#main').load('../tally/entryListByCategory.php?'+rnd(),'',function(){     
			  Entry.searchByCategory();
		   });
	  }
	 
	 
	 Account = function(){}
	 Category = function(){}
	 Account.pg = new Page('listtb');
	 Category.pg = new Page("listtb");
	 Entry.searchByAccount = function(){
		
		 $('#dataView').html(LOADING);   
		 url = '../tally/entry_accountListQry.php?';
		 if (Account.pg.params && !Account.pg.flag) {url +=Account.pg.params;}
		        submitSearch('entrySchForm',url+rnd(),'dataView',function(){
		        	Account.pg.query = Entry.search; 
		        	Account.pg.init();
		        	Account.pg.flag='';
		        	$('#searchbar #subjectCate').val('account');
		        });
	 }  
	 
	 Entry.searchByCategory = function(){
		 $('#dataView').html(LOADING);   
		 url = '../tally/entry_categoryListQry.php?';
		 if (Category.pg.params && !Category.pg.flag) {url +=Category.pg.params;}
		        submitSearch('entrySchForm',url+rnd(),'dataView',function(){
		        	Category.pg.query = Entry.search; 
		        	Category.pg.init();  
		        	Category.pg.flag='';
		        	$('#searchbar #subjectCate').val('category');
		        });
	 }
	 
	 //判断查询按账户还是收支类别
	 Entry.search = function(subjectId){
		 if(subjectId){ //消除分页bug
			 Account.pg.flag='1';
			 Category.pg.flag='1';
		 }
		 if(subjectId && subjectId!='0'){//赋值到查询条件里
			 $('#entrySchForm #subjectId').val(subjectId);
		 }
		 var mode = $('#tally_board #account').attr('class'); //查询方式
		 if(mode=="active"){
			 Entry.searchByAccount();
			 Help.show(220);
		 }else{
			 Entry.searchByCategory();
			 Help.show(221);
		 }
	 }
	 
	 Entry.dailyBalance = function(){
		 url = ctx+'/tally/dailyBalance.php?';
  	 $("#main").load(url+rnd(),function(){
  		 Help.show(301,0); 
  		 $('#dataView').html(LOADING);
  		 $('#dataView').load(ctx+'/tally/dailyBalanceQry.php?',function(){
  			 Entry.pg.init();
  		 });
  	 });
	 }
	 
	 Entry.receivableList = function(){
		 url = ctx+'/tally/receivableList.php?';
  	 $("#main").load(url+rnd(),function(){
  		 Help.show(301,0);
  		 $('#dataView').html(LOADING);
  		 $('#dataView').load(ctx+'/tally/receivableListQry.php?',function(){
  			 Entry.pg.init();
  		 });
  	 });
	 }
	 
	 Entry.payableList = function(){
		 url = ctx+'/tally/payableList.php?';
  	 $("#main").load(url+rnd(),function(){
  		 Help.show(301,0);
  		 $('#dataView').html(LOADING);
  		 $('#dataView').load(ctx+'/tally/payableListQry.php?',function(){
  			 Entry.pg.init();
  		 });
  	 });
	 }
	 
	 Entry.payableSummry = function(){
		 url = ctx+'/tally/payableSummry.php?';
  	 $("#main").load(url+rnd(),function(){
  		 Help.show(301,0);
  		 $('#dataView').html(LOADING);
  		 $('#dataView').load(ctx+'/tally/payableSummryQry.php?',function(){
  			 Entry.pg.init();
  		 });
  	 });
	 }
	 
	 Entry.payableAccountList = function(){
	    
	    url = ctx+'/tally/payableAccountList.php?';
	    $("#main").load(url+rnd(),function(){
 		 	Help.show(301,0);
 		 	$('#dataView').html(LOADING);
 		 	$('#dataView').load(ctx+'/tally/payableAccountListQry.php?',function(){
 			 Entry.pg.init();
 		 });
	    });
	 }
	 
	 Entry.creditList = function(){
		    
		url = ctx+'/tally/creditList.php?';
		$("#main").load(url+rnd(),function(){
	   		Help.show(301,0);
	   		$('#dataView').html(LOADING);
	   		$('#dataView').load(ctx+'/tally/creditListQry.php?',function(){
 			 Entry.pg.init();
 		 });
		});
	}
	 
	 
	 Entry.onExport = function(){
		 var mode = $('#tally_board #account').attr('class'); //查询方式
		 if(mode=="active"){
			 submitExport('entrySchForm',ctx+'/tally/entry_exportByAccount.php?'+rnd());
		 }else{
			 submitExport('entrySchForm',ctx+'/tally/entry_exportByCategory.php?'+rnd());
		 }
	 }
   
	  
   
	  
	  
	  
	
	